package net.swissbite.VolumeCallPriceCalc.models;

/**
 * Copyright (C) 2011  David Daester
 * 
 * This file is part of VolumeCallPriceCalc.
 *
 * VolumeCallPriceCalc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * VolumeCallPriceCalc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with VolumeCallPriceCalc.  If not, see <http://www.gnu.org/licenses/>.
 */
import java.util.Date;

/**
 * Model for identifier (call-number), sum of duration and count of calls.
 * 
 * @author David Däster
 * 
 */
public class IdDurNumbModel {

	String identifier;
	Long duration;
	int counts, month, year;

	/**
	 * Returns the number of the month.
	 * 
	 * @return Number in 1..12
	 */
	public int getMonth() {
		return month;
	}

	/**
	 * Returns the years since 1990.
	 * 
	 * @return years since 1990.
	 */
	public int getYearsSince1900() {
		return year;
	}

	/**
	 * Returns the canonical year.
	 * 
	 * @return canonical year.
	 */
	public int getYear() {
		return year + 1900;
	}

	/**
	 * Returns the duration to this caller.
	 * 
	 * @return sum of all durations.
	 */
	public Long getDuration() {
		return duration;
	}

	/**
	 * Adds a duration to this called number. Increases the counter.
	 * 
	 * @param duration
	 */
	public void addDuration(Long duration) {
		assert duration >= 0;
		this.duration += duration;
		++counts;
	}

	/**
	 * Returns the identifier.
	 * 
	 * @return identifier
	 */
	public String getIdentifier() {
		return identifier;
	}

	/**
	 * Returns the counts of calls.
	 * 
	 * @return counts of calls.
	 */
	public int getCounts() {
		return counts;
	}

	/**
	 * Constructor with identifier and a date.
	 * 
	 * @param identifier
	 *            number of calling partner as {@link String}.
	 * @param date
	 *            a starting date. Used for setting month and year to this
	 *            model.
	 */
	public IdDurNumbModel(String identifier, Date date) {
		this(identifier, date.getMonth(), date.getYear());
	}

	/**
	 * 
	 * Constructor with identifier and a date.
	 * 
	 * @param identifier
	 *            number of calling partner as {@link String}.
	 * @param month
	 *            Month for this model.
	 * @param year
	 *            Year for this model.
	 */
	public IdDurNumbModel(String identifier, int month, int year) {
		this.identifier = identifier;
		this.counts = 0;
		this.duration = 0l;
		this.month = month;
		this.year = year;

	}

	/**
	 * Returns the date as the first day of the month.
	 * 
	 * @return The first day of the month in this data representation.
	 */
	public Date getDate() {
		return new Date(year, month, 1);
	}

	@Override
	public String toString() {
		return identifier + ": " + duration + "s :#" + counts;
	}

}
